// subpackage/clock-in/add/index.js
var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default,
  t = require("../../../@babel/runtime/helpers/objectSpread2"),
  r = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  i = require("../../../@babel/runtime/helpers/slicedToArray"),
  n = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  a = require("../../../utils/tools/index"),
  s = require("../../../config/index"),
  u = require("../../../components/base/m-button/index"),
  d = e(require("../behavior"));
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgs: [],
    submitFileList: [],
    submitFileIdList: []
  },
  behaviors: [s.default],
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  preview(e) {
    wx.previewImage({
      urls: this.data.submitFileList,
      current: e.currentTarget.dataset.index
    })
  },
  handleDeleteFile(e) {
    var submitFileList = this.data.submitFileList
    var submitFileIdList = this.data.submitFileIdList
    var imgs = this.data.imgs
    submitFileList.splice(e.currentTarget.dataset.index, 1)
    submitFileIdList.splice(e.currentTarget.dataset.index, 1)
    imgs.splice(e.currentTarget.dataset.index, 1)
    this.setData({
      submitFileList: submitFileList,
      submitFileIdList: submitFileIdList,
      imgs:imgs
    })
    this.selectComponent("#form").setValues({
      images: this.data.imgs
    })
  },
  chooseImage() {
    wx.navigateTo({
      url: '/subpackage/common/camera/index',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },
  onSubmit(e) {
    console.log(this.selectComponent("#form"))

    console.log(e)
    $.request['POST/business/engineering/log/clockIn']({
      engineeringId: 5,
      finishFileIdList: [446]
    })
  },
  addimgs() {
    this.selectComponent("#form").setValues({
      images: this.data.imgs
    })
  },
  onSubmit: (0, u.apply)(n(r().mark((function e() {
    var i, n, a, s, u, d, o, c, m, p, h, f, _, v;
    return r().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          return a = this.data, s = a.uu_id, u = a.mode, d = a.useTypeValue, e.next = 11, this.selectComponent("#form").verify({
            project: [{
              required: !0,
              message: "请选择项目"
            }],
            images: [{
              required: !0,
              message: "请添加照片"
            }]
          });
        case 6:
          if (o = e.sent) {
            e.next = 9;
            break
          }
          return e.abrupt("return", void $.msg("请选择机械用途"));
        case 9:
          if (o.detail && !((null === (i = o.detail) || void 0 === i ? void 0 : i.length) < 5)) {
            e.next = 11;
            break
          }
          return e.abrupt("return", void $.msg("设备简介必须大于5个字符"));
        case 11:
          o = e.sent, console.log(o), $.request['POST/business/engineering/log/clockIn']({
            engineeringId: o.project.id,
            submitFileIdList: o.images.map((function (e) {
              return e.id
            })),
            submitFileList: o.images.map((function (e) {
              return e.url
            }))
          }).then(res => {
            res = res[0]
            if (res.code == 20002) {
              let pages =getCurrentPages()
              let prevpage = pages[pages.length - 2];
              prevpage.getList()
              $.msg("打卡成功"), setTimeout((function () {
                $.router.back({
                  params: {
                    "page-type": "publish"
                  }
                })
              }), 2000)
            } else {
              wx.showToast({
                title: res.msg,
                icon: "none"
              })
            }
          });
        case 13:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))),
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})